import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class Test {

    public List<List<Integer>> generate(int numRows) {
        List<List<Integer>> list = new ArrayList<>();

        List<Integer> head = new ArrayList<>();
        head.add(1);
        list.add(head);

        for (int i = 1; i < numRows; i++) {
            // 开始
            List<Integer> cur = new ArrayList<>();
            cur.add(1);

            // 中间
            for (int j = 1; j < i; j++) {
                List<Integer> prev = list.get(i-1);
                int midVal = prev.get(j-1) + prev.get(j);
                cur.add(midVal);
            }

            // 最后
            cur.add(1);

            list.add(cur);
        }

        return list;
    }

    public static void main(String[] args) {
        List<List<Integer>> list = new ArrayList<>();

        List<Integer> tmp0 = new ArrayList<>();
        tmp0.add(1);
        tmp0.add(2);
        list.add(tmp0);

        List<Integer> tmp1 = new ArrayList<>();
        tmp1.add(10);
        tmp1.add(20);
        list.add(tmp1);

        /*List<Integer> ret = list.get(1);
        System.out.println(ret);*/

        int ret = list.get(1).get(1);
        System.out.println(ret);


    }

    public static void main3(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();

        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        System.out.println(list);

        System.out.println("===============");

        for (int i = 0; i < list.size(); i++) {
            Integer a = list.get(i);
            System.out.print(a + " ");
        }
        System.out.println();
        System.out.println("===============");

        for (int i : list) {
            System.out.print(i + " ");
        }
        System.out.println();

        System.out.println("======迭代器======");
        Iterator<Integer> it = list.iterator();
        while (it.hasNext()){
            System.out.print(it.next() + " ");
        }
        System.out.println();

        System.out.println("=====迭代器2====");

        // 默认是从0开始打印
        // ListIterator<Integer> it2 = list.listIterator();
        // 从指定位置开始打印
        ListIterator<Integer> it2 = list.listIterator(2);
        while(it2.hasNext()){
            System.out.print(it2.next() + " ");
        }
        System.out.println();

        System.out.println("=====迭代器3=====");
        ListIterator<Integer> it3 = list.listIterator(list.size());
        while (it3.hasPrevious()){
            System.out.print(it3.previous() + " ");
        }
        System.out.println();
    }

    public static void main2(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();

        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        // list.add(0,99);
        System.out.println(list);

        System.out.println("================");

        // [1,3)
        List<Integer> subList = list.subList(1, 3);
        System.out.println(subList);
        subList.set(0, 99);
        System.out.println(subList);
        System.out.println(list);

        Integer ii = 3;
        list.remove(ii);
        System.out.println(list);

        // list.clear();

        ArrayList<Integer> list1 = new ArrayList<>();
        list1.addAll(list);
        System.out.println(list1);

        list1.add(999);
        System.out.println(list1);
    }

    public static void main1(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        System.out.println(list);

        ArrayList<Integer> list2 = new ArrayList<>(15);
        list2.add(11);
        list2.add(21);
        list2.add(31);
        System.out.println(list2);

        ArrayList<String> list4 = new ArrayList<>();
        ArrayList<Integer> list3 = new ArrayList<>(list2);
        System.out.println(list3);
    }
}
